//
//  MRCustomNotificationsCell.m
//  MoRan
//
//  Created by MoRan Team on 2023.
//  Copyright © 2023 MoRan Team. All rights reserved.
//

#import "MRCustomNotificationsCell.h"

@implementation MRCustomNotificationsCell

- (void)awakeFromNib {
    // Initialization code
    [super awakeFromNib];
}

- (void)setData:(id)data delegate:(id)delegate {

    if ([data isKindOfClass:[NSDictionary class]]) {
        if ([data[@"data"] isKindOfClass:[MRCustomNotificationsCellModel class]]) {
            MRCustomNotificationsCellModel *model = data[@"data"];
            _model = model;
            
            _titleLabel.text = model.msg.title;
            
            NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:model.msg.title attributes:@{NSStrikethroughStyleAttributeName : @(NSUnderlineStyleNone)}];
            [attrStr setAttributes:@{NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle),
                                         NSBaselineOffsetAttributeName : @0}
                                 range:NSMakeRange(0, model.msg.title.length)];
            _title1Label.attributedText = attrStr;
            
            if (model.index == 0) {
                _icoImageView.image = [UIImage imageNamed:@"select"];
                _titleLabel.hidden = NO;
                _title1Label.hidden = YES;
            } else {
                _icoImageView.image = [UIImage imageNamed:@"unselect"];
                _titleLabel.hidden = YES;
                _title1Label.hidden = NO;
            }
    
            _subTitleLabel.text = model.msg.subTitle;
            _contentLabel.text = model.msg.content;
            CGSize size = [model.msg.content ex_sizeWithFont:[UIFont systemFontOfSize:18] constrainedToSize:CGSizeMake(kScreenWidth - 68, MAXFLOAT)];
            _contentHeight.constant = size.height + 6;
            _timeLabel.text = model.msg.time;
        }
    }
}

+ (float)getCellFrame:(id)msg {

    if ([msg isKindOfClass:[MRCustomNotificationsCellModel class]]) {
        MRCustomNotificationsCellModel *model = msg;

        CGSize size = [model.msg.content ex_sizeWithFont:[UIFont systemFontOfSize:18] constrainedToSize:CGSizeMake(kScreenWidth - 68, MAXFLOAT)];
        
        if (model.msg.subTitle.length > 0) {
            return 133 + size.height - 18;
        }
        
        return 133 + size.height - 18 - 28;
    }
    
    return 60;
}

@end


#pragma mark - Model

@implementation MRCustomNotificationsCellModel

+ (MRCustomNotificationsCellModel *)ittemModelWithIndex:(NSInteger)index msg:(MRNotificationModel *)msg {
    MRCustomNotificationsCellModel *model = [MRCustomNotificationsCellModel new];
    model.index = index;
    model.msg = msg;
    return model;
}

@end
